import { FC, useRef } from "react"
import Child from "./Child"

//暴露的方法
export type Ifocus = {
    getFocus: (value?: string) => boolean
}

const Imperative: FC<any> = () => {
    //需求:
    // 父组件点击按钮,让子组件的input获得焦点
    // 通过ref获取子组件暴露的方法
    let f = useRef<Ifocus | null>(null)
    return (
        <fieldset>
            <legend>暴露方法</legend>
            <h1>这是个父组件</h1>
            <Child ref={f} name="韩梅梅" />
            <button onClick={()=>{
             f.current?.getFocus()
            }}>父组件的按钮</button>
        </fieldset>
    )
}

export default Imperative